<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\user\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use app\user\model\Cuser as CuserModel;
use app\user\model\Continent as ContinentModel;
/**
 * 用户列表控制器
 * @package app\user\admin
 */
class User extends Admin
{
    /**
     * @author 李洪波 <361951119@qq.com>
     * @return mixed
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function index()
    {

        $data_list = CuserModel::where($this->getMap())
            ->order($this->getOrder('id DESC'))
            ->paginate();
        if($data_list->items()){
            foreach ($data_list->items() as &$val){
                $country=ContinentModel::where(['id'=>$val['country'],'type'=>'country'])->value('name');
                $val['country']=$country;
            }
        }
        $countries=ContinentModel::where(['type'=>'country'])->column(['id','name']);
        return ZBuilder::make('table')
            ->hideCheckbox()
            ->setTableName('user')
            ->addColumns([
                ['id', 'ID'],
                ['phone', 'Account'],
                ['username', 'User Name'],
                ['email', 'Email'],
                ['country', 'Country'],
                ['status', 'Status', 'status','',[-1=>'cancellation',1=>'normal']],
            ])
            ->setSearchArea([
                ['select', 'status', 'Status', '', '', [-1=>'cancellation',1=>'normal']],
                ['select', 'country', 'Country', '', '', $countries],
                ['text', 'username', 'User Name','like']
            ])
            ->setRowList($data_list)
            ->fetch();
    }
}
